package com.demo.admin.executor.job.handler;

import com.demo.admin.executor.service.ICustomerService;
import com.xxl.job.core.biz.model.ReturnT;
import com.xxl.job.core.handler.annotation.XxlJob;
import com.xxl.job.core.log.XxlJobLogger;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Component;

/**
 * @ClassName: DemoCleanCustomerHandler
 * @Description:
 * @Author: Liu ZiQi
 * @create: 2020/12/15 11:41
 **/
@Component
public class DemoCleanCustomerHandler {

    private Logger logger = LoggerFactory.getLogger(DemoCleanCustomerHandler.class);

    @Value("${apollo.test}")
    private String test;

    @Autowired
    private ICustomerService customerService;

    @XxlJob("CleanCustomerJobHandler")
    public ReturnT<String> cleanCustomerJobHandler(String param) throws Exception {
        XxlJobLogger.log("XXL-JOB-START, Clean Customer Job.");
        logger.info("XXL-JOB-START, Clean Customer Job.");

        try {
            System.out.println(test);
            customerService.cleanCustomer();
        } catch (Exception e) {
            XxlJobLogger.log("XXL-JOB-END-ERROR, Clean Customer Job.", e);
            logger.error("XXL-JOB-END-ERROR, Clean Customer Job.", e);
            return ReturnT.FAIL;
        }
        XxlJobLogger.log("XXL-JOB-END-SUCCESS, Clean Customer Job.");
        logger.info("XXL-JOB-END-SUCCESS, Clean Customer Job.");
        return ReturnT.SUCCESS;
    }
}
